package com.ruoyi.leave.service.impl;


import com.ruoyi.common.utils.DocUtils;
import com.ruoyi.common.utils.OfficeUtils;
import com.ruoyi.leave.domain.LeaveApply;
import com.ruoyi.leave.service.IParentKnowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.FileInputStream;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * OfficeServiceImpl :
 *
 * @author zyw
 * @create 2024-06-24  15:41
 */
@Service
public class ParentKnowServiceImpl implements IParentKnowService {


    @Resource
    private ResourceLoader resourceLoader;


    @Override
    public XWPFDocument getParentKnow(LeaveApply query) {
        try {
            FileInputStream fileInputStream = DocUtils.convertInputStreamToFileInputStream(resourceLoader.getResource("classpath:templates/doc1.docx").getInputStream());
            XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream);
            // 替换文本数据构建
            OfficeUtils.paragraphTextFilling(xwpfDocument,OfficeUtils.objectToMap(query));
            return xwpfDocument;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public void getParentKnowWord(XWPFDocument document, LeaveApply query, HttpServletResponse response) {
        OfficeUtils.processingWordResponses("家长知情同意书-" + query.stuName, OfficeUtils.writeDocumentToInputStream(document), response);
    }



}
